package cn.buk.qms.web;

import cn.buk.api.wechat.dto.JsSdkParam;
import cn.buk.api.wechat.dto.WeixinUserInfo;
import cn.buk.api.wechat.entity.WeixinOauthToken;
import cn.buk.api.wechat.service.WeixinService;
import cn.buk.tms.selfservice.FlightOrderSelfService;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.*;

/**
 *
 * @author yfdai
 * @date 2017/2/6
 */
@Profile({"weixin-service"})
@RestController
@RequestMapping("/wx-service")
public class WeixinController extends BaseController {

  public static Logger logger = LogManager.getLogger(WeixinController.class);

  @Value("${owner_enterprise_id}")
  private int ownerId;

  @Autowired
  private WeixinService weixinService;

  @Autowired
  private FlightOrderSelfService service;

  /**
   * 不需要登录，如果获取了openid，则认为处于登录状态
   *
   * @param code
   * @return
   */
  @RequestMapping("/getOpenId")
  public WeixinOauthToken searchOpenid(@RequestParam("code") String code) {
    return weixinService.getOauthToken(this.ownerId, code);
  }

  @RequestMapping("/jssdk_config")
  public JsSdkParam getJsSdkConfig(@RequestParam("url") String url) {
    return weixinService.getJsSdkConfig(this.ownerId, url);
  }

  @RequestMapping("/getUserInfo")
  public WeixinUserInfo searchUserInfo(@RequestParam("openid") String openid) {
    return weixinService.getUserInfo(this.ownerId, openid);
  }



}
